package com.csii.excelapp.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import org.springframework.util.StringUtils;
import java.io.Serializable;
import com.alibaba.fastjson.JSONObject;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResponseDto<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private boolean success = true;
    private String message = "操作成功！";
    private Integer code = 0;
    private T ResponseDto;
    private long timestamp = System.currentTimeMillis();
    private String onlTable;

    public ResponseDto() {
    }

    public ResponseDto<T> success(String message) {
        this.message = message;
        this.code = MesCodeConstants.SUCCESS;
        this.success = true;
        return this;
    }

    public static <T> ResponseDto<T> ok() {
        ResponseDto<T> r = new ResponseDto();
        r.setSuccess(true);
        r.setCode(MesCodeConstants.SUCCESS);
        r.setMessage("成功");
        return r;
    }

    public static <T> ResponseDto<T> ok(String msg) {
        ResponseDto<T> r = new ResponseDto();
        r.setSuccess(true);
        r.setCode(MesCodeConstants.SUCCESS);
        r.setMessage(msg);
        return r;
    }

    public static <T> ResponseDto<T> ok(T data) {
        ResponseDto<T> r = new ResponseDto();
        r.setSuccess(true);
        r.setCode(MesCodeConstants.SUCCESS);
        r.setResponseDto(data);
        return r;
    }

    public static <T> ResponseDto<T> error(String msg) {
        return error(MesCodeConstants.FAIL, msg);
    }

    public static <T> ResponseDto<T> error(int code, String msg) {
        ResponseDto<T> r = new ResponseDto();
        r.setCode(code);
        r.setMessage(msg);
        r.setSuccess(false);
        return r;
    }

    public static <T> ResponseDto<T> error(SentinelEnum sentinelEnum) {
        ResponseDto<T> r = new ResponseDto();
        r.setCode(sentinelEnum.getType());
        r.setMessage(sentinelEnum.getDescription());
        r.setSuccess(false);
        return r;
    }

    public ResponseDto<T> error500(String message) {
        this.message = message;
        this.code = MesCodeConstants.FAIL;
        this.success = false;
        return this;
    }

    public static ResponseDto<Object> noauth(String msg) {
        return error(MesCodeConstants.NO_AUTH, StringUtils.isEmpty(msg) ? "资源受限" : msg);
    }

    public String toString() {
        return JSONObject.toJSONString(this);
    }

    public boolean isSuccess() {
        return this.success;
    }

    public String getMessage() {
        return this.message;
    }

    public Integer getCode() {
        return this.code;
    }

    public T getResponseDto() {
        return this.ResponseDto;
    }

    public long getTimestamp() {
        return this.timestamp;
    }

    public String getOnlTable() {
        return this.onlTable;
    }

    public void setSuccess(final boolean success) {
        this.success = success;
    }

    public void setMessage(final String message) {
        this.message = message;
    }

    public void setCode(final Integer code) {
        this.code = code;
    }

    public void setResponseDto(final T ResponseDto) {
        this.ResponseDto = ResponseDto;
    }

    public void setTimestamp(final long timestamp) {
        this.timestamp = timestamp;
    }

    public void setOnlTable(final String onlTable) {
        this.onlTable = onlTable;
    }

    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof ResponseDto)) {
            return false;
        } else {
            ResponseDto<?> other = (ResponseDto) o;
            if (!other.canEqual(this)) {
                return false;
            } else if (this.isSuccess() != other.isSuccess()) {
                return false;
            } else {
                label65:
                {
                    Object this$message = this.getMessage();
                    Object other$message = other.getMessage();
                    if (this$message == null) {
                        if (other$message == null) {
                            break label65;
                        }
                    } else if (this$message.equals(other$message)) {
                        break label65;
                    }

                    return false;
                }

                Object this$code = this.getCode();
                Object other$code = other.getCode();
                if (this$code == null) {
                    if (other$code != null) {
                        return false;
                    }
                } else if (!this$code.equals(other$code)) {
                    return false;
                }

                Object this$ResponseDto = this.getResponseDto();
                Object other$ResponseDto = other.getResponseDto();
                if (this$ResponseDto == null) {
                    if (other$ResponseDto != null) {
                        return false;
                    }
                } else if (!this$ResponseDto.equals(other$ResponseDto)) {
                    return false;
                }

                if (this.getTimestamp() != other.getTimestamp()) {
                    return false;
                } else {
                    Object this$onlTable = this.getOnlTable();
                    Object other$onlTable = other.getOnlTable();
                    if (this$onlTable == null) {
                        if (other$onlTable != null) {
                            return false;
                        }
                    } else if (!this$onlTable.equals(other$onlTable)) {
                        return false;
                    }

                    return true;
                }
            }
        }
    }

    protected boolean canEqual(final Object other) {
        return other instanceof ResponseDto;
    }

    public int hashCode() {
        boolean PRIME = true;
        int result = 1;
        result = result * 59 + (this.isSuccess() ? 79 : 97);
        Object $message = this.getMessage();
        result = result * 59 + ($message == null ? 43 : $message.hashCode());
        Object $code = this.getCode();
        result = result * 59 + ($code == null ? 43 : $code.hashCode());
        Object $ResponseDto = this.getResponseDto();
        result = result * 59 + ($ResponseDto == null ? 43 : $ResponseDto.hashCode());
        long $timestamp = this.getTimestamp();
        result = result * 59 + (int) ($timestamp >>> 32 ^ $timestamp);
        Object $onlTable = this.getOnlTable();
        result = result * 59 + ($onlTable == null ? 43 : $onlTable.hashCode());
        return result;
    }
}
